package com.example.controller;

import com.example.entity.Admin;
import com.example.entity.MI_Table;
import com.example.entity.RespBean;
import com.example.entity.Result;
import com.example.mapper.MedInfoQueryMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库存信息查询
 *
 * @author: liu
 * 2022-03-30-10:48
 **/
@Api(tags = "MedInfoQueryController")
@RestController
@ResponseBody
public class MedInfoQueryController{

    @Autowired
    private MedInfoQueryMapper medInfoQueryMapper;

    @ApiOperation(value = "根据用户ID查询库存类别信息")
    @GetMapping(value = "/queryKindsByID/{userid}")
    public List<MI_Table> queryKindsByID(@PathVariable int userid) {
//        System.out.println("admin.getId() is " + admin.getId());
        return medInfoQueryMapper.queryKinds(userid);
    }

    @ApiOperation(value = "根据药品名称查询库存信息")
    @GetMapping(value = "/wareHouseQueryByName")
    public Result queryAllByName(String m_name) {
        return Result.getSuccess().setData(medInfoQueryMapper.queryAllByName(m_name));
    }

    @ApiOperation(value = "根据用户ID查询库存信息")
    @PostMapping(value = "/wareHouseQueryByID")
    @ResponseBody
    public List<MI_Table> queryAllOrderByID(@RequestBody Admin admin) {
        System.out.println("admin.getId() is " + admin.getId());
        return medInfoQueryMapper.queryAllById(admin.getId());
    }

    @ApiOperation(value = "根据用户ID修改库存信息")
    @PostMapping(value = "/updWareByID/{m_inventory}&{m_userid}&{m_id}")
    public RespBean updTheWare(@PathVariable int m_inventory, @PathVariable int m_userid,@PathVariable int m_id){
        System.out.printf("updTheWare: the m_inventory,m_userid,m_id is "+m_inventory+m_userid+m_id);
        if(m_inventory != 0){
            medInfoQueryMapper.updMedInfoWare(m_inventory,m_userid,m_id);
            return RespBean.success("修改成功");
        }else {
            return RespBean.error("修改失败");
        }

    }

//    public Result queryAllOrderByID() {
//        return Result.getSuccess().setData(medInfoQueryMapper.queryAllById());
//    }
}
